<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="utf-8">
		<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
		<title>确认订单</title>
		<meta content="yes" name="apple-mobile-web-app-capable">
		<meta content="black" name="apple-mobile-web-app-status-bar-style">
		<meta content="telephone=no" name="format-detection">
		<meta content="on" http-equiv="x-dns-prefetch-control">

		<link rel="stylesheet" href="${pageContext.request.contextPath}/bettery/js/jquery.confirm/jquery.confirm.css">
		<link rel="stylesheet" href="${pageContext.request.contextPath}/bettery/css/life.css">
		<script type="text/javascript" src="${pageContext.request.contextPath}/dewei/js/jquery.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/bettery/js/jquery.confirm/jquery.confirm.js"></script>
		<script src="${pageContext.request.contextPath}/bettery/js/jquery-ui-1.10.4.custom.min.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/bettery/js/template.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/bettery/js/bettery_common.js"></script>
		<style type="text/css">
		body {
			-moz-user-select: none;
			background: none repeat scroll 0 0 #fff;
			color: #666;
			font-family: Helvetica, STHeiti STXihei, Microsoft JhengHei,
				Microsoft YaHei, Arial;
			font-size: 14px;
			height: 100%;
			line-height: 1.5;
			margin: 0 auto;
			max-width: 640px;
			min-width: 320px;
		}
		</style>
		<script type="text/javascript">
</script>

	</head>
	<body>
		<input type="hidden" value="${lat}" name='lat' id="hiddenbLat" />
		<input type="hidden" value="${lng}" name='lng' id="hiddenbLng" />
		<div id="wrapBody" class="wx_wrap">
			<div id="pagePay">

				<div style="opacity: 1;" class="address_defalut" id="addressDefault" href="#" onclick="toEditAddr();">
					<s:hidden id="wxaddress_id" name="wxaddress.id"></s:hidden>
					<h3>
						送至
					</h3>
					<ul>
						<li>
							${wxaddress.province}${wxaddress.city}${wxaddress.town}${wxaddress.address}
						</li>
						<li>
							<strong>${wxaddress.cname}</strong>${wxaddress.mobi}
						</li>
						<li style="display: none;" class="error">
							请选择乡镇/街道
						</li>
					</ul>
				</div>

				<div style="opacity: 1;" class="address_defalut" id="addressDefault">
					<h3>
						输入卡号
					</h3>
					<input type="text" id="carNo" style="border: 0 none; color: #333; font-size: 14px; height: 20px; line-height: normal; vertical-align: bottom; width: 90%; padding-left: 30px; font-size: 14px;" maxlength="25" placeholder="请输入一卡通号码" name="carNo"
						value="${carNo}">
				</div>
				<div style="-webkit-transform-origin: 0px 0px; opacity: 1; -webkit-transform: scale(1, 1);" class="order_info" id="orderInfo">
					<h3>
						订单信息
					</h3>
					<ul id="productList">

					</ul>
				</div>
				<div style="-webkit-transform-origin: 0px 0px; opacity: 1; -webkit-transform: scale(1, 1);" class="pay_area" id="payArea">
					<p class="price">
						总价：
						<strong id="pageTotalPrice">¥5399.00</strong>
					</p>
					<p style="" id="payBtnList" class="action">
						<a style="" class="tenpay" id="btnTenpay" href="javascript:queryMend();">门店自取</a>
						<a style="" href="javascript:saveDingdanDirect();">送货上门</a>
					</p>
					
					<p style=""  class="action">
						<font color="red" >*</font>选择送货上门需要另收服务费￥${sessionScope.cardserverPrice}元。
					</p>
					<p style=""  class="action">
						<font color="red" >*</font>选择门店自取、送货上门均需要3天左右到货。
					</p>
				</div>
			</div>
		</div>
		<script id="test" type="text/html">
{{each list as value i}}
<li class="hproduct">
	<img alt="" src="{{value.imgUrl}}"  onerror="this.src='${pageContext.request.contextPath}/bettery/img/category.jpg'"  class="photo">
	<p class="fn">{{value.name}}</p>
	<p class="sku"><em>品牌：</em><span>{{value.pinpai}}</span></p>
	<p class="sku"><em>型号：</em><span>{{value.guige}}</span></p>
	<p class="sku"><em>价格：</em><span>￥{{value.cardprice}}</span> 
	<span class="tag" style="display: none;" id="pingouPriceTag"></span></p>
	<p class="sku"><em>数量：</em>
	<span><span>{{value.buyNum}}</span><input type="tel" value="{{value.buyNum}}" ids="{{value.id}}" price="{{value.cardprice}}"  class="count" style="display: none;"></span>
	</p>
</li>
{{/each}}
</script>

		<script type="text/javascript">
var goodsJson = ${goodsJson};
	$(function(){
		if(null!=goodsJson&&goodsJson.length>0)
		{
			for(var i=0;i<goodsJson.length;i++){
				if(goodsJson[i].cardprice){
					goodsJson[i].cardprice=parseFloat(goodsJson[i].cardprice,10).toFixed(2);
				}
			}
			var data={list:goodsJson};
			var html = template('test', data);
			document.getElementById('productList').innerHTML = html;
			calcTotal();
		}
	});
	
	function toEditAddr(){
		var lat=$("#hiddenbLat").val();
		var lng=$("#hiddenbLng").val();
		var fix="?lat="+lat+"&lng="+lng;
		$(".count").each(function(){
			var num=$(this).val();
			var ids=$(this).attr("ids");
			fix=fix+"&ids="+ids+"&buyNums="+num;
		});
		this.location.href="queryAddrManage.do"+fix;
	}

	function FloatMul(arg1,arg2){
		var m=0,s1=arg1.toString(),s2=arg2.toString(); 
		try{m+=s1.split(".")[1].length;}catch(e){}
		try{m+=s2.split(".")[1].length;}catch(e){}
		return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
		}   
		
		function FloatAdd(arg1,arg2){
		var r1,r2,m;
		try{r1=arg1.toString().split(".")[1].length;}catch(e){r1=0;} 
		try{r2=arg2.toString().split(".")[1].length;}catch(e){r2=0;}
		m=Math.pow(10,Math.max(r1,r2)) ; 
		return (arg1*m+arg2*m)/m;
		}
	function calcTotal(){
		var total=0;
		$(".count").each(function(){
			var price=$(this).attr("price");
			var num=$(this).val();
			if(num>0){
				total=FloatAdd(total,FloatMul(price,num));
			}
		});
		$("#pageTotalPrice").html("¥"+total.toFixed(2));
	}
	function saveDingdanDirect(){
		var carNo=$("#carNo").val();
		if(""==carNo){
			$.confirm({'title' : '提示','message' : "请填写一卡通卡号",'buttons' :{'确定' :{'class' : 'blue','action' : function(){}}}});
			return ;
		}
		var r = /^(([A-Z]{1})+\d{7})$/;　　//正整数 
		if(!r.test(carNo)){
			$.confirm({'title' : '提示','message' : "一卡通卡号格式错误",'buttons' :{'确定' :{'class' : 'blue','action' : function(){}}}});
			return ;
		}
		var lat=$("#hiddenbLat").val();
		var lng=$("#hiddenbLng").val();
		var wxaddress_id=$("#wxaddress_id").val();
		var fix="?lat="+lat+"&lng="+lng+"&id="+wxaddress_id+"&carNo="+carNo;
		$(".count").each(function(){
			var num=$(this).val();
			var ids=$(this).attr("ids");
			fix=fix+"&ids="+ids+"&buyNums="+num;
		});
		this.location.href="saveDingdanDirect.do"+fix;
	}
	function queryMend(){
		var carNo=$("#carNo").val();
		if(""==carNo){
			$.confirm({'title' : '提示','message' : "请填写一卡通卡号",'buttons' :{'确定' :{'class' : 'blue','action' : function(){}}}});
			return ;
		}
		var r = /^(([A-Z]{1})+\d{7})$/;　　//正整数 
		if(!r.test(carNo)){
			$.confirm({'title' : '提示','message' : "一卡通卡号格式错误",'buttons' :{'确定' :{'class' : 'blue','action' : function(){}}}});
			return ;
		}
		
		var lat=$("#hiddenbLat").val();
		var lng=$("#hiddenbLng").val();
		var wxaddress_id=$("#wxaddress_id").val();
		if(lat&&lng){
			    $("#preloader").show();
				var fix="?lat="+lat+"&lng="+lng+"&id="+wxaddress_id+"&carNo="+carNo;
				$(".count").each(function(){
					var num=$(this).val();
					var ids=$(this).attr("ids");
					fix=fix+"&ids="+ids+"&buyNums="+num;
				});
				this.location.href="queryNearMend.do"+fix;
		}else{
			navigator.geolocation.getCurrentPosition(function(position)
			{
				_lat = position.coords.latitude;
				_lng = position.coords.longitude;
				getConvertLatLng(_lat, _lng);
			}, function(error)
			{
			  switch (error.code)
				{
					case error.TIMEOUT :
						var msg = "获取位置超时！您可通过点击消息界面【左下角键盘按钮】，打开【+】按钮，点击【位置】按钮，手动发送您当前位置！";
						$.confirm({'title' : '提示','message' : msg,'buttons' :{'确定' :{'class' : 'blue','action' : function(){}}}});
						break;
					case error.PERMISSION_DENIED :
						var msg = "您拒绝了使用位置共享服务，查询已取消！";
						$.confirm({'title' : '提示','message' : msg,'buttons' :{'确定' :{'class' : 'blue','action' : function(){}}}});
						break;
					case error.POSITION_UNAVAILABLE :
						var msg = "获取位置失败！您可通过点击消息界面【左下角键盘按钮】，打开【+】按钮，点击【位置】按钮，手动发送您当前位置！";
						$.confirm({'title' : '提示','message' : msg,'buttons' :{'确定' :{'class' : 'blue','action' : function(){}}}});
						break;
				}
			},
			{
				maximumAge : 10000,
				timeout : 10000,
				enableHighAccuracy : true
			});
		}
	}
	function getConvertLatLng(lat, lng)
	{
			$.getJSON("../gpsparse.jsp",
			{
				lat : lat,
				lng : lng
			}, function(data)
			{
				if (data.error == 0)
				{
				$("#hiddenbLng").val(data.lng);
				$("#hiddenbLat").val(data.lat);
				queryMend();
				}
				else
				{
				$.confirm({'title' : '提示','message' : "地理坐标转换失败",'buttons' :{'确定' :{'class' : 'blue','action' : function(){}}}});
				}
			});
	}
</script>
<div id="preloader" style="display: none;"></div>
	</body>
</html>